package interview.huawei.training.p36;

import java.util.Iterator;
import java.util.Scanner;
import java.util.LinkedHashSet;
import java.lang.StringBuilder;

public class Main {
    public static void main(String[] args) {
        String letterMap = "abcdefghijklmnopqrstuvwxyz";
        LinkedHashSet<Character> set = new LinkedHashSet();
        StringBuilder sb = new StringBuilder();
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextLine()) {
            // 密钥
            String secretKey = scanner.nextLine();
            // 明文
            String plainText = scanner.nextLine();
            for(char ch : secretKey.toCharArray()) {
                set.add(ch);
            }
            for(char ch : letterMap.toCharArray()) {
                set.add(ch);
            }

            int index = 0;
            for(Character ch : plainText.toCharArray()) {
                // 获取当前ch在letterMap中的索引
                index = ch - 'a';
                Iterator<Character> iterator = set.iterator();
                while(iterator.hasNext()) {
                    Character secretCh = iterator.next();
                    if(index == 0) {
                        sb.append(secretCh);
                    }
                    index--;
                }

            }
            System.out.println(sb);
            sb.delete(0, sb.length());
            set.clear();
        }
    }
}